<template>
	<div class="changewhite">
		<Row style="margin-top:15px;text-align: left;">   			
		        <Col span="24">
		        	<Card style="width:880px;margin: auto;">
		        		<Spin size="large" fix v-if="loadingShow"></Spin>
		        		<p slot="title" style="text-align:center">
				              	 新增评价计算
				        </p>
				        <Row style="text-align: center;">   			
		        			<Col span="12">
					        	<span>名称：</span>
								<Input v-model="calculationname"  placeholder="请输入评价名称" style="width:200px"></Input>
		        			</Col>	
		        			<Col span="12">
					        	<span>年级：</span>
								<Select :label-in-value=true @on-change="gradechange" v-model="gradeselect" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in gradelist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[0]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>基数：</span>
								<Select v-model="highBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in highBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
		        			<Col span="12">
					        	<span>本次：</span>
								<Select v-model="highThis" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in highThislist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[1]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>入学考试：</span>
								<Select v-model="midBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
		        			<Col span="12">
					        	<span>本次：</span>
								<Select v-model="midThis" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midThislist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[2]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>初一考试：</span>
								<Select v-model="midFirstBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midFirstBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row v-if="toggleshow[3]" style="margin-top:10px;text-align: center;">   			
		        			<Col span="12">
					        	<span>初二考试：</span>
								<Select v-model="midSecondBase" filterable placeholder="输入快速匹配" style="width:200px">
					                <Option v-for="item in midSecondBaselist" :value="item.value" :key="item.value">{{ item.label }}</Option>
					            </Select>
		        			</Col>
						</Row>
						<Row>
					    	<Col span="24" style="margin-top:15px;text-align: center;">
					    		<Button type="ghost" @click="chance" icon="close-round">取消</Button>
					    		<Button @click="addcalculation" type="primary"  icon="checkmark-round">保存</Button>
					    	</Col>
					    </Row> 
				    </Card>
		        </Col>			        
			</Row>
	</div>
</template>

<script>
	import api from "@/components/js/Apidomain.js"
	
	export default{
		data(){
			return{
				loadingShow:false,				//面板菜单获取的加载中显示隐藏
				
				gradeselectlabel:"",			//年级选择的label值
				
				calculationname:"",			//输入的名称
				gradeselect:"",				//年级选择
				highBase:"",				//高中基数
				highThis:"",				//高中本次
				
				midBase:"",					//初中入学
				midThis:"",					//初中本次
				midFirstBase:"",			//初一下学期期末
				midSecondBase:"",			//初二下学期期末
				
				toggleshow:[],					//切换初中高中的基数成绩输入框
				
				
				gradelist: [
//                  {value: '1',label: '高一'},
//                  {value: '2',label: '初一'},
//                  {value: '3',label: '初二'},
//                  {value: '4',label: '初三'},
                ],
                highBaselist:[],
                highThislist:[],
                midBaselist:[],
                midThislist:[],
                midFirstBaselist:[],
                midSecondBaselist:[]
			}
		},
		created(){
			this.getgradelist();
		},
		methods:{
			chance:function(){
				this.$emit('chance')
			},
			gradechange:function(value){
				this.gradeselectlabel = value.label;
				if(value.label.indexOf("高") > -1){
					this.toggleshow = [true,false,false,false]
				}
				if(value.label.indexOf("初一") > -1){
					this.toggleshow = [false,true,false,false]
				}
				if(value.label.indexOf("初二") > -1){
					this.toggleshow = [false,true,true,false]
				}
				if(value.label.indexOf("初三") > -1){
					this.toggleshow = [false,true,true,true]
				}
				this.getalllist();
			},
			getgradelist:function(){
           		this.loadingShow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/tchStudent/getTchGradeSelect';
            	this.$http.post(url, {}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
						self.gradelist = response.data.data
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00167',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
           	},
           	//根据年级id去获取添加的剩下的下拉框值
           	getalllist:function(){
           		this.loadingShow = true;
           		var self = this;
            	let url = api.apidomain+'/tqes/web/quaPerformance/getPerforByGradeId';
            	this.$http.post(url, {gradeId:this.gradeselect}).then(function(response) {
					if(response.data.success == true){
						
//						////console.log(response.data.data)
//						self.gradelist = response.data.data
						self.highBaselist = response.data.data.highBase 
		                self.highThislist = response.data.data.highThis 
		                self.midBaselist = response.data.data.midBase 
		                self.midThislist = response.data.data.midThis 
		                self.midFirstBaselist = response.data.data.midFirstBase 
		                self.midSecondBaselist = response.data.data.midSecondBase
		                
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00168',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
           	},
           	addcalculation:function(){
           		if(this.gradeselectlabel == "" || this.calculationname == ""){
					this.$Message.error({
								content: "请完善信息后再提交",
								duration: 10,
								closable: true
							});	
					return;
				}
           		if(this.gradeselectlabel.indexOf("初") > -1){
           			var senddata = {
						"name":this.calculationname, 						//评价名称
						"gradeId":this.gradeselect,					//年级ID
						"baseExamId":this.midBase,				//基数考试ID
						"firstOverExamId":this.midFirstBase,			//初一下学期期末考试ID
						"secondOverExamId":this.midSecondBase,			//初二下学期期末考试ID
						"thisExamId":this.midThis,				//本次考试ID
					}
           		}else{
           			var senddata = {
						"name":this.calculationname, 						//评价名称
						"gradeId":this.gradeselect,					//年级ID
						"baseExamId":this.highBase,				//基数考试ID
						"thisExamId":this.highThis,				//本次考试ID
					}
           		}
           		this.loadingShow = true;
				var self = this;
            	let url = api.apidomain+'/tqes/web/quaPerformance/algorithm';
//          	let url = 'http://192.168.43.196'+'/tqes/web/quaPerformance/algorithm';
            	this.$http.post(url,senddata).then(function(response) {
					if(response.data.success == true){
						self.$Message.success({
		                    content: '保存成功',
		                    duration: 10,
		                    closable: true
               			})
						self.$emit('chance')
						self.loadingShow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingShow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00169',
							duration: 10,
							closable: true
						});
						self.loadingShow = false;
					});
           		
           	}
		}
	}
</script>

<style lang="css" scoped>
	.changewhite >>> .ivu-card-body{
		padding: 12px 15px;
		background-color: white;
	}
</style>